﻿using Cbs.Lucky.Model;
using Cbs.Lucky.Properties;
using Cbs.Lucky.Services;
using Cbs.Lucky.Services.Impl;
using Cbs.Lucky.ViewModels;
using Cbs.Lucky.Views;
using Dapper;
using Dapper.Contrib.Extensions;
using DryIoc;
using NLog;
using Prism.Ioc;
using Prism.Modularity;
using System;
using System.Data;
using System.Data.SQLite;
using System.Windows;

namespace Cbs.Lucky
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        private static Logger Logger = LogManager.GetCurrentClassLogger();
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void OnInitialized()
        {
            base.OnInitialized();
            //var ctr = Container.Resolve<IContainer>();
            //ctr.Register<IDataItemService,DataItemService>(Reuse.Singleton);
            //var service = Container.Resolve<IDataItemService>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            try
            {
                containerRegistry.RegisterInstance<IDbConnection>(new SQLiteConnection(Settings.Default.DbConn));
                containerRegistry.RegisterSingleton<IDataItemService, DataItemService>();

                //containerRegistry.RegisterForNavigation<CreateOrUpdate, CreateOrUpdateViewModel>(nameof(CreateOrUpdate));
                //containerRegistry.RegisterForNavigation<LoseQuery, LoseQueryViewModel>(nameof(LoseQuery));
            }
            catch (Exception ex)
            {
                Logger.Error($"IOC失败 Message:{ex.Message},StackTrace:{ex.StackTrace}");
            }
        }
    }
}
